Skip to content

Fix cloud app hanging on Cloudflare Workers - #121

Merged
RhysSullivan merged 1 commit into
mainfrom
fix-cloud-workers-db
Apr 9, 2026
Merged

Fix cloud app hanging on Cloudflare Workers#121
RhysSullivan merged 1 commit into
mainfrom
fix-cloud-workers-db

Conversation

@RhysSullivan

Copy link
Copy Markdown
Collaborator

Summary

  • Use pg.Client instead of pg.Pool — Hyperdrive manages connection pooling externally
  • Remove Effect.runSync(Scope.make()) and Layer.memoize at module top level — this pattern holds resources across the module lifecycle which causes the DB connection to hang during Workers' restricted init context
  • Make public API handler construction lazy (deferred to first request)

Root cause

Layer.memoize with a top-level Scope attempted to establish and hold a DB connection during module initialization. Workers restrict I/O during init, causing the connection to hang indefinitely and triggering "Worker's code had hung" errors.

Test plan

  • /api/auth/me returns 401 (no hang)
  • /api/auth/login redirects to WorkOS with HTTPS callback URL
  • /api/debug/db confirmed Hyperdrive → Planetscale connection works
  • Full sign-in flow on executor.sh

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 9, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
executor-marketing 7b3632f Commit Preview URL

Branch Preview URL
Apr 09 2026, 12:12 AM

- Use pg.Client instead of pg.Pool (Hyperdrive manages pooling)
- Remove Layer.memoize/Scope at module top level (hangs in Workers init)
- Make public API handler lazy
- Remove debug endpoint
@RhysSullivan
RhysSullivan force-pushed the fix-cloud-workers-db branch from 801b118 to 7b3632f Compare April 9, 2026 00:10
@RhysSullivan
RhysSullivan merged commit 65c5a7c into main Apr 9, 2026
2 checks passed
RhysSullivan added a commit that referenced this pull request May 31, 2026
- Use pg.Client instead of pg.Pool (Hyperdrive manages pooling)
- Remove Layer.memoize/Scope at module top level (hangs in Workers init)
- Make public API handler lazy
- Remove debug endpoint
@RhysSullivan
RhysSullivan deleted the fix-cloud-workers-db branch June 11, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant